package com.douguo.recipe;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class EKActivity extends DouguoActivity {
	private Button mBtnHot;
	private Button mBtnMeishi;
	private Button mBtnJiankang;
	private Button mBtnZiwei;
	private Button mBtnChufang;
	private int mCurrentPos;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		mCurrentPos = 0;
		if(bundle != null) {
			mCurrentPos = bundle.getInt("pos");
		}
		
	}
	
	
	protected void onStart () {
		super.onStart();
		enableTab();
	}
	
	public int getCurrentTabPos(){
		return mCurrentPos;
	}
	
	protected void enableTab() {

		mBtnHot = (Button) findViewById(R.id.ek_sort_button_hot);
		
		mBtnHot.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(EKActivity.this, EKMainActivity.class);
				Bundle bundle = new Bundle();
				bundle.putInt("pos", 0);
				
				intent.putExtras(bundle);
				intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
				startActivity(intent);
			}
		});
		
		mBtnMeishi = (Button) findViewById(R.id.ek_sort_button_meishi);
		mBtnMeishi.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),EKArticleListActivity.class);
				Bundle bundle = new Bundle();
				bundle.putInt("pos", 1);
				bundle.putString("sortId", "1");
				bundle.putString("title", getString(R.string.ek_sort_meishi));
				intent.putExtras(bundle);
				intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
				startActivity(intent);
				
			}
		});
		mBtnJiankang = (Button) findViewById(R.id.ek_sort_button_jiankang);
		
		mBtnJiankang.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),EKArticleListActivity.class);
				Bundle bundle = new Bundle();
				bundle.putInt("pos", 2);
				bundle.putString("sortId", "134");
				bundle.putString("title", getString(R.string.ek_sort_jiankang));
				intent.putExtras(bundle);
				intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
				startActivity(intent);
				
			}
		});
		mBtnZiwei = (Button) findViewById(R.id.ek_sort_button_ziwei);
		
		mBtnZiwei.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),EKArticleListActivity.class);
				Bundle bundle = new Bundle();
				bundle.putInt("pos", 3);
				bundle.putString("sortId", "133");
				bundle.putString("title", getString(R.string.ek_sort_ziwei));
				intent.putExtras(bundle);
				intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
				startActivity(intent);
				
			}
		});
		mBtnChufang = (Button) findViewById(R.id.ek_sort_button_chufang);
		
		mBtnChufang.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),EKArticleListActivity.class);
				Bundle bundle = new Bundle();
				bundle.putInt("pos", 4);
				bundle.putString("sortId", "6");
				bundle.putString("title", getString(R.string.ek_sort_chufang));
				intent.putExtras(bundle);
				intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
				startActivity(intent);
				
			}
		});
		switch(mCurrentPos){
		case 0:
			mBtnHot.setBackgroundResource(R.drawable.tab_on);
			mBtnHot.setOnClickListener(null);
			break;
		case 1:
			mBtnMeishi.setBackgroundResource(R.drawable.tab_on);
			mBtnMeishi.setOnClickListener(null);
			break;
		case 2:
			mBtnJiankang.setBackgroundResource(R.drawable.tab_on);
			mBtnJiankang.setOnClickListener(null);
			break;
		case 3:
			mBtnZiwei.setBackgroundResource(R.drawable.tab_on);
			mBtnZiwei.setOnClickListener(null);
			break;
		case 4:
			mBtnChufang.setBackgroundResource(R.drawable.tab_on);
			mBtnChufang.setOnClickListener(null);
			break;
		}
	}
}
